package com.xxcxcxcx.jobsystem.common.component;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

//gui显示一个图片的类
@OnlyIn(Dist.CLIENT)
public class ImageWidget extends AbstractWidget {
    private ResourceLocation resourceLocation;
    private int xTexStart;
    private int yTexStart;
    private int textureWidth;
    private int textureHeight;
    //以上参数参考ImageButton
    public void setTextureWidth(int newWidth)
    {
        textureWidth = newWidth;
    }
    public ImageWidget(int x, int y, int width, int height, Component message, ResourceLocation resourceLocation,
    int xTexStart, int yTexStart, int textureWidth, int textureHeight) {
        super(x, y, width, height, message);
        this.resourceLocation = resourceLocation;
        this.xTexStart = xTexStart;
        this.yTexStart = yTexStart;
        this.textureWidth = textureWidth;
        this.textureHeight = textureHeight;
        //渲染内容在材质上的位置和宽窄
    }

    @Override
    //不知道是干啥用的
    public void updateNarration(NarrationElementOutput p_169152_) {
        this.defaultButtonNarrationText(p_169152_);
    }

    @Override
    public void render(PoseStack poseStack, int MouseX, int MouseY, float partialTick) {
        RenderSystem.setShaderColor(1.0f,1.0f,1.0f,1.0f);
        RenderSystem.setShaderTexture(0, this.resourceLocation);
        RenderSystem.enableDepthTest();
        blit(poseStack, this.x, this.y, this.xTexStart, yTexStart, textureWidth, textureHeight);
    }
}
